﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using AMS.UI.Forms;
using AMS.UI.Controls;
using AMS.ComponentModel;
using AMS.UI.Menu;

namespace AMS.Trademark.Management
{
    public partial class FrmMain : BaseMainForm
    {
        public FrmMain()
        {
            InitializeComponent();
            FrmMainModel.Instance.MainForm = this;
            FrmMainModel.Instance.MenuBar = dsMenu;
            FrmMainModel.Instance.StatusBar = barStatus;

            if (!ControlUtility.DesignMode)
            {
                //barLeft.MinimumSize = new Size(180, 100);
                tsMain.Tabs.Clear();

                mainMenu = new BarMainMenu();
                mainMenu.MainForm = this;
                mainMenu.MenuControl = bar1;
                mainMenu.MenuFileName = @"..\menu\tm-management.xml";
                mainMenu.AuthorizeToAll = true;
                mainMenu.CreateMenu(true, null);

                ////FrmMainModel.Instance.ShowWorkForm(typeof(FrmRecvFileRepository));
                ////FrmMainModel.Instance.ShowWorkForm(typeof(FrmTaskRepository));
                ////FrmMainModel.Instance.ShowWorkForm(typeof(FrmTaskDocConfig));
                ////FrmMainModel.Instance.ShowWorkForm(typeof(FrmRecvFileTaskConfig));
                //FrmMainModel.Instance.ShowWorkForm(typeof(FrmRecvFileTaskConfigByCase));
                ////FrmMainModel.Instance.ShowWorkForm(typeof(FrmTaskDocConfig));
            }
        }

        private IMainMenu mainMenu;

        private void menuItem_Click(object sender, EventArgs e)
        {
            ButtonItem ctrl = sender as ButtonItem;
            string tag = ctrl.Tag as string;

            ShowForm(tag);
        }

        private void ShowForm(string tag)
        {
            Type formType = null;
            switch (tag.ToLower())
            {
                case "rf":
                    formType = typeof(FrmRecvFileRepository);
                    break;

                case "rftask":
                    formType = typeof(FrmRecvFileTaskConfig);
                    break;

                case "rftask_case":
                    formType = typeof(FrmRecvFileTaskConfigByCase);
                    break;

                case "task":
                    formType = typeof(FrmTaskRepository);
                    break;

                case "taskdoc":
                    formType = typeof(FrmTaskDocConfig);
                    break;

                case "doc":
                    formType = typeof(FrmDocsRepository);
                    break;

                default:
                    break;
            }

            if (formType != null)
            {
                FrmMainModel.Instance.CheckAndShowForm(formType, tag);
            }
        }

        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            ObjectUtility.Dispose();
            ////foreach (Form frm in MdiChildren)
            ////{
            ////    frm.Dispose();
            ////    frm.Close();
            ////}

            ////bar1.Dispose();
            ////tsMain.Tabs.Clear();
        }

        ////public void ShowForm(Form frm)
        ////{
        ////    frm.MdiParent = this;
        ////    frm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
        ////    frm.Dock = DockStyle.Fill;
        ////    frm.WindowState = FormWindowState.Maximized;
        ////    frm.Show();
        ////    frm.BringToFront();
        ////}
    }
}
